extends Unit
class_name EnemyPurple

@export var animated_sprite_2d:AnimatedSprite2D
@export var charecter_body_2d:CharacterBody2D

func _physics_process(delta: float) -> void:
	var driection:Vector2 = GameInputEvent.movenment_input()
	if driection == Vector2.UP:
		animated_sprite_2d.play("walk")
	elif driection == Vector2.DOWN:
		animated_sprite_2d.play("walk")
	elif driection == Vector2.LEFT:
		if !animated_sprite_2d.flip_h:
			animated_sprite_2d.flip_h = true
		animated_sprite_2d.play("walk")
	elif driection == Vector2.RIGHT:
		if animated_sprite_2d.flip_h:
			animated_sprite_2d.flip_h = false
		animated_sprite_2d.play("walk")
	
	if driection == Vector2.ZERO:
		animated_sprite_2d.play("idle")
	
	charecter_body_2d.position.x = clamp(charecter_body_2d.position.x,-1000,1000)
	charecter_body_2d.position.y = clamp(charecter_body_2d.position.y,-1000,1000)
	
	charecter_body_2d.velocity = driection * state.speed
	charecter_body_2d.move_and_slide()
